package leetcode.all;

public class Solution859 {

    public boolean buddyStrings(String s, String goal) {
        int n = s.length();
        if(goal.length()!=n) return false;
        StringBuilder sb = new StringBuilder(s);
        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                if(swap(sb,i,j).equals(goal)) return true;
            }
        }
        return false;
    }

    public String swap(StringBuilder sb, int i, int j){
        char tmp = sb.charAt(i);
        sb.setCharAt(i,sb.charAt(j));
        sb.setCharAt(j,tmp);
        return sb.toString();
    }
}
